package com.suxin.nio;

import com.firenio.codec.lengthvalue.LengthValueCodec;
import com.firenio.codec.lengthvalue.LengthValueFrame;
import com.firenio.component.*;

/**
 * @author Tang
 * @classname SimpleClient
 * @description [  ]
 * @date 2021/2/5 9:56
 */
public class SimpleClient {

    public static void main(String[] args) throws Exception{
        ChannelConnector context = new ChannelConnector("127.0.0.1", 8300);
        IoEventHandle eventHandle = new IoEventHandle() {
            @Override
            public void accept(Channel ch, Frame f) throws Exception {
                System.out.println();
                System.out.println("____________________" + f.getStringContent());
                System.out.println();
                context.close();
            }
        };

        context.setIoEventHandle(eventHandle);
        context.addChannelEventListener(new LoggerChannelOpenListener());
        context.addProtocolCodec(new LengthValueCodec());
        Channel ch    = context.connect(3000);
        LengthValueFrame frame = new LengthValueFrame();
        frame.setString("hello server!", ch);
        ch.writeAndFlush(frame);
    }

}